home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / mc220.zip / MC-VS-SC.DOC < prev    next >
Text File  |  1992-02-24  |  20KB  |  462 lines

  1.     
  2.     
  3.     
  4.     
  5.     
  6.     
  7.     
  8.     
  9.     
  10.     
  11.     
  12.     
  13.                                        A
  14.                                    Comparison
  15.                                        of
  16.     
  17.     
  18.           ===========================================================
  19.           MM   MM  IIIIIII    CCCC   RRRRRR     OOO             CCCC
  20.           M M M M     I      C    C  R     R   O   O           C    C
  21.           M  M  M     I     C        R     R  O     O         C
  22.           M     M     I     C        RRRRRR   O     O  -----  C
  23.           M     M     I     C        R   R    O     O         C
  24.           M     M     I      C    C  R    R    O   O           C    C
  25.           M     M  IIIIIII    CCCC   R     R    OOO             CCCC
  26.           ===========================================================
  27.           
  28.                                      A N D
  29.           
  30.           ===========================================================
  31.            SSSSS   MM   MM     A     L        L                 CCCC
  32.           S     S  M M M M    A A    L        L                C    C
  33.           S        M  M  M   A   A   L        L               C
  34.            SSSSS   M     M  A     A  L        L        -----  C
  35.                 S  M     M  AAAAAAA  L        L               C
  36.           S     S  M     M  A     A  L        L                C    C
  37.            SSSSS   M     M  A     A  LLLLLLL  LLLLLLL           CCCC
  38.           ===========================================================
  39.     
  40.     
  41.     
  42.     
  43.     
  44.     
  45.     
  46.     
  47.     
  48.     
  49.     
  50.     
  51.     
  52.     
  53.     
  54.                        Copyright 1990,1991 Dave Dunfield
  55.                               All rights reserved
  56.     MICRO-C .vs. SMALL-C                                             Page: 1
  57.  
  58.  
  59.     1. INTRODUCTION
  60.     
  61.           The most common reaction of people hearing about MICRO-C  for  the
  62.        first time is something like "Humph... Another  version  of  the  old
  63.        SMALL-C compiler". This couldn't be further from the truth.
  64.     
  65.                            MICRO-C IS NOT SMALL-C!!!
  66.     
  67.           MICRO-C is a completely  new  implementation  of  a  'C'  compiler
  68.        suitable for use on very small systems. It offers several  advantages
  69.        over SMALL-C:
  70.     
  71.         - It was designed from the  ground  up  to  be  easily  portable  to
  72.           different processors & computer platforms. Sample code  generators
  73.           are included for 8080, 8051, 80x86, 8096, 6809 and  68HC11  cpu's,
  74.           and an entire section of the manual  is  devoted  to  porting  the
  75.           compiler.
  76.     
  77.           Although SMALL-C claims  to  be  easily  portable,  much  of  it's
  78.           arcitecture is oriented toward the original 8080 processor. For an
  79.           example of  how  this  affects  the  compiler,  compare  the  code
  80.           generated by the 8086 version of SMALL-C to reference stack (auto)
  81.           variables to that produced by MICRO-C.
  82.     
  83.         - It is a more complete implementation of the 'C' language, see  the
  84.           features comparison later in this document.
  85.     
  86.         - It produces faster, more compact code. See the  benchmark  results
  87.           later in this document.
  88.     
  89.         - MICRO-C employs  a  fully  tokenized  parser,  allowing  statement
  90.           analysis to be performed  on  16  bit  "tokens"  instead  of  text
  91.           strings as is  done  in  SMALL-C.  This  results  in  MUCH  faster
  92.           compilation.
  93.     
  94.         - Although it is higher in functionality than SMALL-C,  the  MICRO-C
  95.           compiler is much smaller than SMALL-C (Nearly half the size). This
  96.           allows it to run on very small computer systems.
  97.     
  98.     2. DETAILED COMPARISON OF COMPILERS
  99.     
  100.           The following pages contain a detailed comparison of  the  SMALL-C
  101.        version 2 compiler, and MICRO-C.
  102.     MICRO-C .vs. SMALL-C                                             Page: 2
  103.  
  104.  
  105.        2.1 'C' Implementation
  106.             =============================================================
  107.             Data types              | SMALL-C V1 | SMALL-C V2 | MICRO-C |
  108.             ------------------------+------------------------------------
  109.             int                     |    Yes     |    Yes     |   Yes   |
  110.             char                    |    Yes     |    Yes     |   Yes   |
  111.             unsigned int            |     No     |     No     |   Yes   |
  112.             unsigned char           |     No     |     No     |   Yes   |
  113.             pointers                |    Yes     |    Yes     |   Yes   |
  114.             pointers to pointers    |     No     |     No     |   Yes   |
  115.             Single dimension arrays |    Yes     |    Yes     |   Yes   |
  116.             Multi dimension arrays  |     No     |     No     |   Yes   |
  117.             arrays of pointers      |     No     |     No     |   Yes   |
  118.             Typecast                |     No     |     No     |   Yes   |
  119.             sizeof                  |     No     |     No     |   Yes   |
  120.             ========================+====================================
  121.             Control Structures      | SMALL-C V1 | SMALL-C V2 | MICRO-C |
  122.             ------------------------+------------------------------------
  123.             if/else                 |    Yes     |    Yes     |   Yes   |
  124.             while                   |    Yes     |    Yes     |   Yes   |
  125.             do/while                |     No     |    Yes     |   Yes   |
  126.             for                     |     No     |    Yes     |   Yes   |
  127.             switch/case             |     No     |    Yes     |   Yes   |
  128.             goto                    |     No     |    Yes     |   Yes   |
  129.             Conditional Expressions |     No     |    Yes     |   Yes   |
  130.             Inline assembler        |    Yes     |    Yes     |   Yes   |
  131.             ========================+====================================
  132.             Pre-processor           | SMALL-C V1 | SMALL-C V2 | MICRO-C |
  133.             ------------------------+------------------------------------
  134.             #define (basic)         |    Yes     |    Yes     |   Yes   |
  135.             #define (Parameterized) |     No     |     No     |   Yes   |
  136.             #define (Multi-line)    |     No     |     No     |   Yes   |
  137.             #undef                  |     No     |     No     |   Yes   |
  138.             #include (single level) |    Yes     |    Yes     |   Yes   |
  139.             #include (nested)       |     No     |    Yes     |   Yes   |
  140.             #ifdef/#ifndef          |     No     |    Yes     |   Yes   |
  141.             ========================+====================================
  142.             Misc features           | SMALL-C V1 | SMALL-C V2 | MICRO-C |
  143.             ------------------------+------------------------------------
  144.             Optimization            |     No     |    Yes     |   Yes   |
  145.             Multiple memory models  |     No     |     No     |   Yes   |
  146.             Make/touch utility      |     No     |     No     |   Yes   |
  147.             Source linker           |     No     |     No     |   Yes   |
  148.             6809 code generator     |     No     |     No     |   Yes   |
  149.             68HC11 code generator   |     No     |     No     |   Yes   |
  150.             8080 code generator     |    Yes     |    Yes     |   Yes   |
  151.             8051 code generator     |     No     |     No     |   Yes   |
  152.             8086 code generator     |     No     |    Yes     |   Yes   |
  153.             8096 code generator     |     No     |     No     |   Yes   |
  154.             ========================+====================================
  155.             Library features        | SMALL-C V1 | SMALL-C V2 | MICRO-C |
  156.             ------------------------+------------------------------------
  157.             Complete standard lib   |     No     |    Yes     |   Yes   |
  158.             Interrupt serial I/O    |     No     |     No     |   Yes   |
  159.             Windowing library       |     No     |     No     |   Yes   |
  160.             TSR support             |     No     |     No     |   Yes   |
  161.             ========================+====================================
  162.     MICRO-C .vs. SMALL-C                                             Page: 3
  163.  
  164.  
  165.        2.2 Generated code quality
  166.     
  167.              To test the actual performace  of  code  generated  by  MICRO-C
  168.           against  code  generated  by  SMALL-C,  I  used  this  "Sieve   of
  169.           Eratosthenes" prime number generator program, taken from the  BYTE
  170.           benchmarks:
  171.     
  172.     
  173.     
  174.     
  175.     
  176.     /*
  177.      * The classic "Sieve of Eratosthenes" prime number program.
  178.      * from BYTE, January 1983.
  179.      */
  180.     #include <stdio.h>
  181.     #include "timer.c"          /* The timer subroutines */
  182.     
  183.     #define SIZE  8190
  184.     #define LOOP  100
  185.     #define TRUE  1
  186.     #define FALSE 0
  187.     
  188.     char flags [SIZE + 1];
  189.     
  190.     main()
  191.     {
  192.         int i, prime, k, count, iter;
  193.     
  194.         printf("BYTE Sieve Benchmark - %d iterations\n",LOOP);
  195.     
  196.     /* Start timer and execute loop */
  197.         startimer(timestamp);
  198.         for(iter = 1; iter <= LOOP; ++iter) {
  199.             count = 0;                          /* prime counter */
  200.             for(i = 0; i <= SIZE; ++i)          /* set all flags true */
  201.                 flags [i] = TRUE;
  202.             for(i = 0; i <= SIZE; ++i) {
  203.                 if(flags [i]) {                 /* found a prime */
  204.                     prime = i + i + 3;          /* twice index + 3 */
  205.     /*              printf ("\n%d", prime);     */
  206.                 for(k = i + prime; k <= SIZE; k+= prime)
  207.                     flags [k] = FALSE;          /* kill all multiple */
  208.                 ++count; } } }                  /* primes found */
  209.         elapsed(timestamp);                     /* Calculate time taken */
  210.     
  211.     /* Report results */
  212.         printf("%d primes.\n\n", count);        /* primes found on 100th pass */
  213.         printf("Elapsed time: %02d:%02d:%02d.%02d\n",
  214.             timestamp[1], timestamp[0], timestamp[3], timestamp[2]);
  215.     }
  216.     MICRO-C .vs. SMALL-C                                             Page: 4
  217.  
  218.  
  219.        2.3 Speed of compilation
  220.     
  221.              To show the relative compilation times,  I  wrote  this  simple
  222.           MICRO-C program, using the timing routines shown below, to execute
  223.           the compilers & report the time taken:
  224.     
  225.     
  226.     
  227.     
  228.     
  229.     #include <stdio.h>
  230.     #include "timer.c"          /* The timer subroutines */
  231.     
  232.     main()
  233.     {
  234.         startimer(timestamp);
  235.         system("CC SIEVE");             /* Execute the SMALL-C compiler */
  236.         elapsed(timestamp);
  237.         printf("Elapsed time: %02d:%02d:%02d.%02d\n\n",
  238.             timestamp[1], timestamp[0], timestamp[3], timestamp[2]);
  239.     
  240.         startimer(timestamp);
  241.         system("MCC SIEVE.C SIEVE.ASM");/* Execute the MICRO-C compiler */
  242.         elapsed(timestamp);
  243.         printf("Elapsed time: %02d:%02d:%02d.%02d\n",
  244.             timestamp[1], timestamp[0], timestamp[3], timestamp[2]);
  245.     }
  246.     
  247.              NOTE: The results from the above program will include the  time
  248.           taken to load the compilers. To minimize this, all tests were  run
  249.           from a RAMdisk. This eliminates disk seek time, and  reduces  load
  250.           time to the speed of a memory to memory copy.
  251.     MICRO-C .vs. SMALL-C                                             Page: 5
  252.  
  253.  
  254.        2.4 Timing the tests
  255.     
  256.              These subroutines were used to time  the  programs,  using  the
  257.           MS-DOS internal clock which has a resolution of 1/100 of a second:
  258.     
  259.     
  260.     
  261.     
  262.     
  263.     char timestamp[4];          /* Stores initial timestamp */
  264.     
  265.     /*
  266.      * Record system time for later calculation
  267.      */
  268.     startimer() asm
  269.     {
  270.             MOV     AH,2CH      ; Get time function
  271.             INT     21H         ; Ask DOS
  272.             MOV     SI,4[BP]    ; Get pointer to timestamp
  273.             MOV     [SI],CX     ; Record hours & minites
  274.             MOV     2[SI],DX    ; Record seconds & hundreds
  275.     }
  276.     
  277.     /*
  278.      * Calculate elapsed time since timestamp recorded
  279.      */
  280.     elapsed() asm
  281.     {
  282.             MOV     AH,2CH      ; Get time function
  283.             INT     21H         ; Ask DOS
  284.             MOV     SI,4[BP]    ; Pointer to timestamp
  285.             SUB     DL,2[SI]    ; Convert 100ths
  286.             JNC     ELAP1       ; No borrow
  287.             ADD     DL,100      ; Re-adjust
  288.             DEC     DH          ; Reduce seconds
  289.     ELAP1:  MOV     2[SI],DL    ; Save elapsed hundreds
  290.             SUB     DH,3[SI]    ; Convert seconds
  291.             JNS     ELAP2       ; No borrow
  292.             ADD     DH,60       ; Re-adjust
  293.             DEC     CL          ; Reduce minites
  294.     ELAP2:  MOV     3[SI],DH    ; Save elapsed seconds
  295.             SUB     CL,[SI]     ; Convert minites
  296.             JNS     ELAP3       ; No borrow
  297.             ADD     CL,60       ; Re-adjust
  298.             DEC     CH          ; Adjust hours
  299.     ELAP3:  MOV     [SI],CL     ; Save elapsed minites
  300.             SUB     CH,1[SI]    ; Convert hours
  301.             MOV     1[SI],CH    ; Save elapsed hours
  302.     }
  303.     MICRO-C .vs. SMALL-C                                             Page: 6
  304.  
  305.  
  306.        2.5 Test results
  307.     
  308.              After compiling the programs, I ran  the  various  tests  on  a
  309.           standard 8-Mhz IBM PC/AT, with these results:
  310.     
  311.     E:\>dir
  312.     
  313.      Volume in drive E is VDISK  V3.3
  314.      Directory of  E:\
  315.     
  316.     CC       EXE    40626   9-10-90  /* SMALL-C compiler */
  317.     MCC      COM    22316   9-10-90  /* MICRO-C compiler */
  318.     TIMER    C       1094   9-10-90  /* The timer subroutines */
  319.     TIMECOMP C        527   9-10-90  /* The compiler timer */
  320.     SIEVE    C       1149   9-10-90  /* The test program */
  321.     SIEVE-S  EXE    16946   9-10-90  /* SMALL-C produced this */
  322.     SIEVE-M  COM     1651   9-10-90  /* MICRO-C produced this */
  323.     TIMECOMP COM     1924   9-10-90  /* Executable compiler timer */
  324.             8 File(s)    301056 bytes free
  325.     
  326.     E:\>sieve-s     /* The SMALL-C version: 1 min, 28.98 secs */
  327.     BYTE Sieve Benchmark - 100 iterations
  328.     1899 primes.
  329.     
  330.     Elapsed time: 00:01:28.98
  331.     
  332.     E:\>sieve-m     /* The MICRO-C version: 1 min, 4.59 secs */
  333.     BYTE Sieve Benchmark - 100 iterations
  334.     1899 primes.
  335.     
  336.     Elapsed time: 00:01:04.59
  337.     
  338.     E:\>
  339.     
  340.     **NOTE: Before running TIMECOMP, I created a "generic" STDIO.H
  341.             file which was suitable for both compilers.
  342.     
  343.     E:\>timecomp    /* Times to compile the program */
  344.     Small-C Compiler, Version 2.1, (Rev. 75)
  345.     Copyright 1982, 1983, 1985 J. E. Hendrix
  346.     Elapsed time: 00:00:04.72       /* SMALL-C 4.72 secs */
  347.     
  348.     MICRO-C 2.0 Compiler
  349.     Copyright 1988,1990 Dave Dunfield
  350.     All rights reserved.
  351.     Elapsed time: 00:00:01.32       /* MICRO-C 1.32 secs */
  352.     
  353.     E:\>
  354.     MICRO-C .vs. SMALL-C                                             Page: 7
  355.  
  356.  
  357.     3. OTHER ADVANTAGES OF MICRO-C
  358.     
  359.           In addition to being a superiour and more portable  compiler,  The
  360.        MICRO-C package also offers these advantages:
  361.     
  362.        3.1 Utilities
  363.     
  364.              MICRO-C Comes with the following utilities (all  with  complete
  365.           MICRO-C source code):
  366.     
  367.         CC      - Command Coordinator, combines pre-processor, compiler,
  368.                   optimizer, assembler and linker into a single command.
  369.                   Command line parameters allow very flexible operation.
  370.     
  371.         MAKE    - Automates building of larger (multi module) programs.
  372.     
  373.         TOUCH   - Set timestamp of file to current or specified date.
  374.                   (Used with MAKEs dependancy checking)
  375.     
  376.         SLINK   - Source LINKer, Allows pre-compiled (assembler) source to
  377.                   be kept in a library and included as needed to resolve
  378.                   external references. Useful when MICRO-C is used as cross
  379.                   compiler for systems not supporting an object linker.
  380.     
  381.         SLIB    - Utility for updating and maintaining a source library.
  382.     
  383.         SINDEX  - Automatically indexes a source library for use by SLINK.
  384.     
  385.         SCONVERT- Converts assembly language source for use by SLINK.
  386.     
  387.         EXE2BIN - Converts MS-DOS EXE files to a binary image, useful for
  388.                   users of later versions of DOS which no longer include
  389.                   this utility.
  390.     
  391.         MCP     - The MICRO-C Pre-processor
  392.     
  393.         MCC     - The MICRO-C Compiler
  394.     
  395.         MCO     - The MICRO-C Optimizer
  396.     MICRO-C .vs. SMALL-C                                             Page: 8
  397.  
  398.  
  399.        3.2 Example Programs
  400.     
  401.              MICRO-C comes with the following  example  programs  (all  with
  402.           complete MICRO-C source code):
  403.     
  404.     ASM86.C         An 8086 assembler
  405.     BASIC.C         A simple BASIC interpreter
  406.     CALC.C          A pop-up (TSR) calculator for programmers
  407.     CASTLE.C        A large "adventure" game
  408.     CHATTR.C        Chenges file attributes
  409.     COMEXT.C        Extracts comment from 'C' programs
  410.     CSET.C          A pop-up (TSR) PC character set
  411.     CVTCOM.C        Convert C++ style '//' comments to C's '/* - */'
  412.     DUMP.C          A HEX/OCTAL file dump utility
  413.     EQUIP.C         Displays equipment installed in your PC
  414.     FIBO.C          Calculates a fibonacci series
  415.     FORTUNE.C       Displays a "fortune cookie" message every time it is run
  416.     GREP.C          Unix like "grep" command from DECUS
  417.     HANOI.C         Solves the "towers of hanoi" program on screen
  418.     HELLO.C         Standard 'C' demo program
  419.     HEM.C           Traps hardware fault interrupts
  420.     HEXED.C         A full-screen hex file editor
  421.     HFTEXT.C        Simple Huffman encoded for text files
  422.     INSTALL.C       The Micro-Install program
  423.     LZC.C           Laser Commander - pop-up (TSR) control for laser printer
  424.     MTERM.C         A pop-up (TSR) ANSI terminal with XMODEM
  425.     OBSCURE.C       Makes a 'C' program un-readable (it still compiles)
  426.     PPC.C           Pretty-Printer for C
  427.     PRIME.C         Calculates prime numbers
  428.     RLTEXT.C        Simple Runn Length encoded for text files
  429.     ROBOFACE.C      Draws a robot face on your BC screen
  430.     TEXTNUM.C       Displays text equivalent of numbers
  431.     TIMEIT.C        Time the execution of another command
  432.     TR.C            Unix like "tr" command
  433.     TTT3D.C         Three-Dimensional Tic-Tac-Toe
  434.     TYPE4.C         Display a file with tabs at 4 character intervals
  435.     VALIDATE.C      PD version McAfee's validate program, uses dual CRC's
  436.     WINDEMO.C       MICRO-C window demonstration program
  437.  
  438.  
  439.  
  440.                               MICRO-C .vs. SMALL-C
  441.  
  442.                                TABLE OF CONTENTS
  443.  
  444.  
  445.                                                                          Page
  446.  
  447.      1. INTRODUCTION                                                        1
  448.  
  449.  
  450.      2. DETAILED COMPARISON OF COMPILERS                                    1
  451.  
  452.         2.1 'C' Implementation                                              2
  453.         2.2 Generated code quality                                          3
  454.         2.3 Speed of compilation                                            4
  455.         2.4 Timing the tests                                                5
  456.         2.5 Test results                                                    6
  457.  
  458.      3. OTHER ADVANTAGES OF MICRO-C                                         7
  459.  
  460.         3.1 Utilities                                                       7
  461.         3.2 Example Programs                                                8
  462.